package com.bmps.springcloud.insuredmicroservice.service.underwrite.strategy.minordeath.riskstrategy;

import com.bmps.springcloud.insuredmicroservice.constant.accept.StrategyConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.LcPolModel;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

/**
 * description:
 * LBT028
 *
 * @author jackdaw
 * @date 2020-01-07 19:19
 */
@Component
public class Lbt028RiskStrategy implements RiskStrategy {

    @Override
    public BigDecimal getAmount(LcPolModel lcPolModel, List<LcPolModel> lcPolModels, boolean current) {

        //年交保费
        BigDecimal prem = lcPolModel.getPrem();
        for (LcPolModel model : lcPolModels) {
            if (StringUtils.equals(model.getRiskCode(), StrategyConstant.HCT007)) {
                if (current || StringUtils.equals(lcPolModel.getPrtNo(), model.getPrtNo())) {
                    prem = prem.add(model.getPrem());
                }
            }
        }
        prem = lcPolModel.getPayIntv() == 1 ? prem.multiply(BigDecimal.valueOf(12)) : prem;
        if (lcPolModel.getPayIntv() == 0) {
            return prem;
        } else if (StrategyConstant.ADULT_AGE - lcPolModel.getInsuredAppAge() >= lcPolModel.getPayYears()) {
            //如果（StrategyConstant.ADULT_AGE-被保险人的投保年龄）大于等于缴费期，则未成年人的身故保额设置为年交保费*缴费期*1
            return prem.multiply(BigDecimal.valueOf(lcPolModel.getPayYears()));
        } else if (StrategyConstant.ADULT_AGE - lcPolModel.getInsuredAppAge() < lcPolModel.getPayYears() && StrategyConstant.ADULT_AGE - lcPolModel.getInsuredAppAge() > 0) {
            //如果（StrategyConstant.ADULT_AGE-被保险人的投保年龄）小于缴费期并且大于0，则未成年人的身故保额设置为年交保费*（StrategyConstant.ADULT_AGE-被保险人的投保年龄）*1
            return prem.multiply(BigDecimal.valueOf(StrategyConstant.ADULT_AGE - lcPolModel.getInsuredAppAge()));
        }
        return BigDecimal.valueOf(0);
    }
}
